package pl.skubicha.domain;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Subjects generated by hbm2java
 */
@Entity
@Table( name = "subjects", catalog = "dziennik" )
public class Subjects implements java.io.Serializable {

	private static final long serialVersionUID = -8596706461596897236L;
 
	private Integer id;
	private Users users;
	private String subjectName;
	private Set< PartialGrades > partialGrades = new HashSet< PartialGrades >( 0 );
	private Set< Groups > groups = new HashSet< Groups >( 0 );
	private Set< FinalGrades > finalGrades = new HashSet< FinalGrades >( 0 ); 

	public Subjects() {
	} 

	public Subjects( final Users users, final String subjectName ) {
		this.users = users;
		this.subjectName = subjectName;
	}
	
	public Subjects( Integer id, String subjectName ) {
		this.id = id;
		this.subjectName = subjectName;
	}

	public Subjects( final Users users, final String subjectName, final Set< PartialGrades > partialGrades, final Set< Groups > groups, final Set< FinalGrades > finalGrades ) {
		this.users = users;
		this.subjectName = subjectName;
		this.partialGrades = partialGrades;
		this.groups = groups;
		this.finalGrades = finalGrades;
	}

	@Id
	@GeneratedValue( strategy = IDENTITY )
	@Column( name = "id_subject", unique = true, nullable = false )
	public Integer getId() {
		return this.id;
	}

	public void setId( final Integer id ) {
		this.id = id;
	}

	@ManyToOne( fetch = FetchType.LAZY )
	@JoinColumn( name = "id_user", nullable = false )
	public Users getUsers() {
		return this.users;
	}

	public void setUsers( final Users users ) {
		this.users = users;
	}

	@Column( name = "subject_name", nullable = false, length = 100 )
	public String getSubjectName() {
		return this.subjectName;
	}

	public void setSubjectName( final String subjectName ) {
		this.subjectName = subjectName;
	}

	@OneToMany( fetch = FetchType.LAZY, mappedBy = "subjects" )
	public Set< PartialGrades > getPartialGrades() {
		return this.partialGrades;
	}

	public void setPartialGrades( final Set< PartialGrades > partialGrades ) {
		this.partialGrades = partialGrades;
	}

	@ManyToMany( fetch = FetchType.LAZY )
	@JoinTable( name = "GroupsSubjects", catalog = "dziennik", 
	joinColumns = { 
			@JoinColumn( name = "Subjects_id_subject", nullable = false, updatable = false ) }, 
			inverseJoinColumns = { @JoinColumn( name = "Groups_id_group", nullable = false, updatable = false ) } )
	public Set< Groups > getGroups() {
		return this.groups;
	}

	public void setGroups( final Set< Groups > groups ) {
		this.groups = groups;
	}

	@OneToMany( fetch = FetchType.LAZY, mappedBy = "subjects" )
	public Set< FinalGrades > getFinalGrades() {
		return this.finalGrades;
	}

	public void setFinalGrades( final Set< FinalGrades > finalGrades ) {
		this.finalGrades = finalGrades;
	}

	public void update( final Users users, final String subjectName, final Set< Groups > groups ) {
		this.users = users;
		this.subjectName = subjectName;
		this.groups = groups;
	}

}
